//
//  SettingViewController.m
//  FastMedical
//
//  Created by 李通 on 16/7/6.
//  Copyright © 2016年 chivalrous. All rights reserved.
//

#import "SettingViewController.h"
#import "SuggestController.h"
#import "SignViewController.h"
#import "ModefiyController.h"

#define kFilePath(fileName) ([NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:fileName])
@interface SettingViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)NSArray *settingArray;
@property(nonatomic,weak)  UITableView *tableView;

@end

@implementation SettingViewController

-(NSArray*)settingArray{
    
    if (_settingArray ==nil) {
        _settingArray = @[@"意见反馈",@"加号符号说明",@"修改密码",@"注销用户"];
        
    }
    return _settingArray;
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds];
    self.tableView =tableView;
    tableView.delegate = self;
    tableView.dataSource =self;
    [self.view addSubview:tableView];
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"settingCell"];
    
    tableView.tableFooterView = [[UIView alloc]init];

    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.settingArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"settingCell" forIndexPath:indexPath];
    cell.textLabel.text = self.settingArray[indexPath.row];
    return cell;
    
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    SuggestController *vc = [[SuggestController alloc]init];
    vc.view.backgroundColor = [UIColor whiteColor];
    if (indexPath.row ==0) {
        
    
    [self.navigationController pushViewController:vc animated:YES];
}
    
    if (indexPath.row ==2) {
        ModefiyController *md = [[ModefiyController alloc]init];
        md.view.backgroundColor = [UIColor whiteColor];
        
        
        
        [self.navigationController pushViewController:md animated:YES];
    }
    
    
    if (indexPath.row ==3) {
        UIAlertController *vc = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"注销后您的用户信息将被清空,您确定要注销吗?" preferredStyle:UIAlertControllerStyleActionSheet];
        
        UIAlertAction *cancelAciton = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
        
        UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            [[NSFileManager defaultManager]removeItemAtPath:kFilePath(@"user.data") error:nil];
            [[NSFileManager defaultManager]removeItemAtPath:kFilePath(@"image.data") error:nil];
            [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"cicty"];
            [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"phoneNumber"];
            //清除所有数据后通知控制器刷新数据
            [[NSNotificationCenter defaultCenter]postNotificationName:@"upload" object:nil];
            
            [self.navigationController popViewControllerAnimated:YES];

        }];
        [vc addAction:confirmAction];
        [vc addAction:cancelAciton];
        
        [self presentViewController:vc animated:YES completion:nil];
        
            }
}



@end
